﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestWF
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.listView1.Items.Add(new ListViewItem(new string[] { "行1列1", "行1列2", "" }));
            this.listView1.Items.Add(new ListViewItem(new string[] { "行2列1", "行1列2", "" }));
            this.listView1.Items.Add(new ListViewItem(new string[] { "行3列1", "行1列2", "" }));

            foreach (ListViewItem item in this.listView1.Items)
            {
                Button btn = new Button();
                btn.Text = "text";
                btn.Name = ""+item.Index;
                this.listView1.Controls.Add(btn);
                btn.Click += this.button_Click;
                btn.Size = new Size(this.listView1.Items[0].SubItems[2].Bounds.Width,
                this.listView1.Items[0].SubItems[2].Bounds.Height);
                btn.Location = new Point(item.SubItems[2].Bounds.Left, item.SubItems[2].Bounds.Top);
            }
        }

        private void button_Click(object sender, EventArgs e)
        {
            MessageBox.Show(this.listView1.SelectedItems[0].SubItems[0].Text);
        }
    }
}
